package com.bilibili.bilibili.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bilibili.bilibili.R;
import com.bilibili.bilibili.model.RegionTypesInfo;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * 作者：郭传沛 on 2017/3/16 18:31
 * 邮箱：bestyourselfgcp@163.com
 * 类用途:
 */

public class RegionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<RegionTypesInfo.DataBean> mDataBeen;
    private Context mContext;

    public RegionAdapter(List<RegionTypesInfo.DataBean> dataBeen, Context context) {
        mDataBeen = dataBeen;
        mContext = context;
    }

    private int[] itemIcons = new int[]{
            R.drawable.ic_category_live, R.drawable.ic_category_t13,
            R.drawable.ic_category_t1, R.drawable.ic_category_t3,
            R.drawable.ic_category_t129, R.drawable.ic_category_t4,
            R.drawable.ic_category_t36, R.drawable.ic_category_t160,
            R.drawable.ic_category_t119, R.drawable.ic_category_t155,
            R.drawable.ic_category_t165, R.drawable.ic_category_t5,
            R.drawable.ic_category_t23, R.drawable.ic_category_t11,
            R.drawable.ic_category_game_center
    };

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemViewHolder viewHolder = new ItemViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_home_region, parent, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
        itemViewHolder.mTitle.setText(mDataBeen.get(position).getName());
        itemViewHolder.mIamge.setImageResource(itemIcons[position]);
    }

    @Override
    public int getItemCount() {
        return mDataBeen.size();
    }

    private class ItemViewHolder extends RecyclerView.ViewHolder {

        private final ImageView mIamge;
        private final TextView mTitle;

        public ItemViewHolder(View itemView) {
            super(itemView);
            mIamge = (ImageView) itemView.findViewById(R.id.item_icon);
            mTitle = (TextView) itemView.findViewById(R.id.item_title);
        }
    }
}
